﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace xiangmu1
{
    public partial class H_Y_XG : Form
    {
        public H_Y_XG()
        {
            InitializeComponent();
        }
        public string kahao;
        
        public void xiugai()
        {
            string kahao2 = this.label2.Text;
            string name2 = txt_huiyuanxingming.Text;

            string sex = string.Empty;
            sex = radioButton1.Checked == true ? "男" : "女";
            string shenfenzheng = dateTimePicker1.Text;
            string phone = txt_huiyuandianhua.Text;
            if (string.IsNullOrEmpty(kahao2) || string.IsNullOrEmpty(name2) || string.IsNullOrEmpty(shenfenzheng) || string.IsNullOrEmpty(phone))
            {
                MessageBox.Show("请填写完整信息", "提示窗口");
                return;
            }
            string sqq = string.Format("select VipId from VipType where TypeName='{0}'", cbo_huiyuanleixing.Text);
            int leixing = (int)FrmHotel.DBHelper.SelectOne(sqq);
            string sql = string.Format(@"update VipInfo set VpName='{0}',VpKaHao='{1}',VpPhone='{2}',VpSex='{3}',VpKaType={4},VpMoney={5},VpShengRi='{6}' where VpId={7}",
                name2, kahao2, phone,  sex,leixing,float.Parse(txt_huiyuankajine.Text), shenfenzheng,kahao);
            int hang = FrmHotel.DBHelper.ExecuteUpdate(sql);
            if (hang > 0)
            {
                MessageBox.Show("修改成功");
                this.DialogResult = DialogResult.OK;
            }
            else
            {
                MessageBox.Show("修改失败");
            }

        }
       
        private void button1_Click(object sender, EventArgs e)
        {
            xiugai();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void txt_huiyuandianhua_TextChanged(object sender, EventArgs e)
        {
           
        }

        private void H_Y_XG_Load(object sender, EventArgs e)
        {
            string sql1 = "select * from VipType";
            DataTable dt = FrmHotel.DBHelper.SelectForTable(sql1);
            cbo_huiyuanleixing.DisplayMember = "TypeName";
            cbo_huiyuanleixing.ValueMember = "VipId";
            cbo_huiyuanleixing.DataSource = dt;

            string sql = string.Format(@"select VpName, VpKaHao, VpPhone, VpSex, TypeName,
                VpMoney,  VpShengRi from VipInfo vi inner join VipType vt on vi.VpKaType = vt.VipId where VpId = '{0}'", kahao);
            SqlDataReader read = FrmHotel.DBHelper.SelectMore(sql);
            while (read.Read())
            {
                this.label2.Text = read["VpKaHao"].ToString();
                this.txt_huiyuanxingming.Text = read["VpName"].ToString();
                this.txt_huiyuandianhua.Text = read["VpPhone"].ToString();
                if(read["VpSex"].Equals("男"))
                {
                    radioButton1.Checked = true;
                }
                else
                {
                    radioButton2.Checked = true;
                }
                this.cbo_huiyuanleixing.Text = read["TypeName"].ToString();
                this.txt_huiyuankajine.Text = read["VpMoney"].ToString();
                this.dateTimePicker1.Value = Convert.ToDateTime(read["VpShengRi"]);
            }
            read.Close();
        }
    }
}
